package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Role;
import sanrenxing.dayEnd.backRepertoryTotal.domain.users;

import java.util.List;

@Repository("ud")
public interface userDao {
  @Insert("insert into users values(seqUsers.nextval,#{userName},#{userPaw},#{userPhone},#{userState},#{roleId})")
  @SelectKey(keyColumn = "userId",keyProperty = "userId", statement = "select userss.NextVal from dual", before = true, resultType = Integer.class)
  public int add(users us);
  @Delete("delete from users where userId=#{us}")
  public int del(int us);
  @Delete("delete from users where roleId=#{us}")
  public int dels(int us);
  @Update("update users set userName=#{userName},userPaw=#{userPaw},userPhone=#{userPhone},userState=#{userState},roleId=#{roleId} where userId=#{userId}")
  public int update(users us);
  @Select("select userId,userName,userPaw,userPhone,userState,roleId from (select rownum r,users.* from users where 1=1 ${xx} and rownum<=${limit}) where r>=${page}")
  public List<users> all(@Param("xx") String xx, @Param("limit") int limit, @Param("page") int page);
  @Select("select count(*) from users where 1=1 ${xx}")
  public int count(String xx);
  @Select("select * from users where userName=#{userName} and userPaw=#{userPaw}")
  public users one(users us);
  @Select("select * from role")
  public List<Role> rfal();

  /**
   * 查询账号是否存在
   * @param userId
   * @param oldPassword
   * @return
   */
  @Select("select count(*) from users where userId=#{userId} and userPaw=#{oldPassword}")
  public int queryPassword(@Param("userId")String userId,@Param("oldPassword")String oldPassword);

  /**
   * 修改新密码
   * @param userId
   * @param newPassword
   * @return
   */
  @Update("update users set userPaw=#{newPassword} where userId=#{userId}")
  public int updatePassword(@Param("userId")String userId,@Param("newPassword")String newPassword);

  /**
   * 根据用户id重置用户密码
   * @param userId
   */
  @Update("update users set userPaw='88888888' where userId=#{userId}")
  public void resetPwd(@Param("userId")String userId);

}
